/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.landmark;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author computer
 */
public class RenameDirFileWithColorCodesGUI extends RenameDirFilesWithColorCodes{
    JFileChooser fc;

    /**
     * Creates new form RenameFileGUI
     */
    public RenameDirFileWithColorCodesGUI() {
        initComponents();
        fc = new JFileChooser();
        
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setMultiSelectionEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtInputFolder = new javax.swing.JTextField();
        btnInputFolder = new javax.swing.JButton();
        txtColorCode = new javax.swing.JTextField();
        btnChangeImageName = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnColorCode = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setBackground(new java.awt.Color(0, 113, 187));
        setFont(new java.awt.Font("Cambria", 0, 11)); // NOI18N

        txtInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnInputFolder.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnInputFolder.setText("...");
        btnInputFolder.setToolTipText("Select the folder with images");
        btnInputFolder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInputFolderActionPerformed(evt);
            }
        });

        txtColorCode.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N

        btnChangeImageName.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnChangeImageName.setText("Rename Files");
        btnChangeImageName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeImageNameActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Color Codes File Path :");

        jLabel2.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Image Folder Path :");

        btnColorCode.setFont(new java.awt.Font("Cambria", 0, 12)); // NOI18N
        btnColorCode.setText("...");
        btnColorCode.setToolTipText("Select the file with colorcodes");
        btnColorCode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnColorCodeActionPerformed(evt);
            }
        });

        jTextArea1.setBackground(new java.awt.Color(51, 51, 51));
        jTextArea1.setColumns(20);
        jTextArea1.setForeground(new java.awt.Color(255, 255, 51));
        jTextArea1.setRows(5);
        jTextArea1.setText("Image folder path is where the images are to be renamed from color code to color description.\nColor codes file path is where the color codes file is present.\nColor code file should be of the format \n\"BOD_054X_White_SM.JPG, 054X_00_zm.jpg\"\nwhere 00 is the color code and White is the color description.");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnChangeImageName))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtInputFolder, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
                                    .addComponent(jLabel1)
                                    .addComponent(txtColorCode))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnInputFolder)
                                    .addComponent(btnColorCode)))
                            .addComponent(jLabel2))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel2)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInputFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnInputFolder))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtColorCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnColorCode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnChangeImageName))
                .addContainerGap(23, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnChangeImageNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeImageNameActionPerformed
        if( txtInputFolder.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(this, "Please select images folder", "Error", JOptionPane.OK_CANCEL_OPTION);            
        }else if( txtColorCode.getText().trim().equals("") ) {
            JOptionPane.showMessageDialog(this, "Please select an color code file", "Error", JOptionPane.OK_CANCEL_OPTION);
        } else {
            Util.getHelperBean().setFolderPath(txtInputFolder.getText());
            Util.getHelperBean().setFilePath(txtColorCode.getText());
            //Util.getHelperBean().setFileExt(cmbExtension.getSelectedItem().toString());
            new RenameDirFileColorCodeSwingWorker().execute();
        }        
    }//GEN-LAST:event_btnChangeImageNameActionPerformed

    private void btnInputFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInputFolderActionPerformed
        if (evt.getSource() == btnInputFolder) {
            int returnVal = fc.showOpenDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtInputFolder.setText(fc.getSelectedFile().toString());
            } else {
                JOptionPane.showMessageDialog(this, "Cancelled");
            }
        } 
    }//GEN-LAST:event_btnInputFolderActionPerformed

    private void btnColorCodeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnColorCodeActionPerformed
        fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        fc.setFileFilter(new FileFiltering());
        if (evt.getSource() == btnColorCode) {
            int returnVal = fc.showOpenDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                txtColorCode.setText(fc.getSelectedFile().toString());
            } else {
                JOptionPane.showMessageDialog(this, "Cancelled");
            }
        } 
    }//GEN-LAST:event_btnColorCodeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChangeImageName;
    private javax.swing.JButton btnColorCode;
    private javax.swing.JButton btnInputFolder;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    protected javax.swing.JTextField txtColorCode;
    protected javax.swing.JTextField txtInputFolder;
    // End of variables declaration//GEN-END:variables
}
